package com.hxkcloud.nurse.utils;

import android.app.Activity;
import android.graphics.drawable.ColorDrawable;
import android.view.Gravity;
import android.view.View;
import android.widget.TextView;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.interfaces.IReturnTrueOrFalse;
import com.hxkcloud.nurse.views.MyBasePopuWindow;

/**
 * Created by Administrator on 2017/2/9.
 */

public class OpenMyPopWindowUtils {
    private static MyBasePopuWindow basPopuWindow;

    public static void dismiss() {

        if (basPopuWindow != null) {
            basPopuWindow.dismiss();
            basPopuWindow = null;
        }
    }

    /**
     * 确认提示框
     *
     * @param activity
     * @param resourseId
     * @param returnTrueOrFalse
     */
    public static void confirm(final Activity activity, int resourseId, String msg, final IReturnTrueOrFalse returnTrueOrFalse) {
        TextView tv_cancel, tv_sure, txt_content;
        View mMenuView;
        basPopuWindow = new MyBasePopuWindow(activity, null,
                R.layout.pop_sure_item);
//		basPopuWindow.setAnimationStyle(R.style.AnimBottom);
        // 显示窗口
        ColorDrawable dw = new ColorDrawable(0x19000000); // 0xb0000000
        // 设置SelectPicPopupWindow弹出窗体的背景
        basPopuWindow.setBackgroundDrawable(dw);
        // 显示窗口
        basPopuWindow.showAtLocation(activity.findViewById(resourseId),
                Gravity.BOTTOM | Gravity.CENTER_HORIZONTAL, 0, 0); // 设置layout在PopupWindow中显示的位置

        mMenuView = basPopuWindow.getmMenuView();
        txt_content = (TextView) mMenuView.findViewById(R.id.txt_content);
        if (msg != null) {
            txt_content.setText(msg);
        }
        tv_cancel = (TextView) mMenuView.findViewById(R.id.tv_cancle);
        tv_sure = (TextView) mMenuView.findViewById(R.id.tv_sure);

        tv_cancel.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                returnTrueOrFalse.returnBoolean(false);
            }
        });
        tv_sure.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                returnTrueOrFalse.returnBoolean(true);
            }
        });
    }
}
